/********************************************************************************
 * Copyright (c)2016-2020, ShenZhen WanJiaAn Technology CO.,LTD.
 * All Rights Reserved.
 *
 * File Name     : DevFlash.c
 * Author        : joki.zhu
 * Date          : 2019-10-28
 *
 * Record        :
 * 1.Date        : 2019-10-28
 *   Author      : joki.zhu
 *   Modification: Created file
 ********************************************************************************/
#include "DevFlash.h"
#include "app_common.h"
#include "spinor.h"

extern int hal_flash_erase(int fd, unsigned long startaddr, unsigned long length);
extern int hal_flash_write(int fd, void *databuf, unsigned long startaddr, unsigned long length);
extern int hal_flash_read(int fd, void *databuf, unsigned long startaddr, unsigned long length);

static FLASH_INFO_S gs_stFlashInfo;

int FlashInit(void)
{
    HI_U64 totalsize = 0;
    HI_U32 pagesize = 0;
    HI_U32 blocksize = 0;
    HI_U32 oobsize = 0;

    spi_raw_get_info(&totalsize, &pagesize, &blocksize, &oobsize, NULL);
    printf("totalsize:%lld pagesize:%d blocksize:%d oobsize:%d\n", totalsize, pagesize, blocksize, oobsize);

    memset(&gs_stFlashInfo, 0, sizeof(gs_stFlashInfo));
    gs_stFlashInfo.stFlashOpsFunc.flash_erase = hal_flash_erase;
    gs_stFlashInfo.stFlashOpsFunc.flash_write = hal_flash_write;
    gs_stFlashInfo.stFlashOpsFunc.flash_read = hal_flash_read;
    
    return 0;
}

FLASH_OPS_FUNC_S *FlashGetOpsHandle(void)
{
    return &gs_stFlashInfo.stFlashOpsFunc;
}

int FlashDeinit(void)
{
    memset(&gs_stFlashInfo, 0, sizeof(gs_stFlashInfo));
    gs_stFlashInfo.stFlashOpsFunc.flash_erase = NULL;
    gs_stFlashInfo.stFlashOpsFunc.flash_write = NULL;
    gs_stFlashInfo.stFlashOpsFunc.flash_read = NULL;
    
    return 0;
}


